package com.kucun.util;


import net.sf.json.JSONObject;
import net.sf.json.JsonConfig;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
/**
 * gson的封装，主要是对字符串的封装
 * @author Administrator
 *
 */
public class GsonUtils {
	
	public static String ChagneDateFormat(Object obj,String formatedatestr) {
		Gson gson = new GsonBuilder().setDateFormat(formatedatestr).create();
		return gson.toJson(obj);
	}
	
	public static String ChagneDateFormat(Object obj) {
		Gson gson = new GsonBuilder().setDateFormat("yyyy-MM-dd HH:mm:ss").create();
		return gson.toJson(obj);
	}
	/**
	 * 封装的转换日期格式
	 * @param obj
	 * @param FormatDate  日期格式 如：yyyy-MM-dd HH:mm:ss
	 * @return 
	 */
public static JSONObject ConvertJsonDateToDate(Object obj,String FormatDate){
	JsonConfig jsonConfig = new JsonConfig();
	jsonConfig.registerJsonValueProcessor(java.util.Date.class, new JsonValueProcessorImpl(FormatDate));
	JSONObject jsonFromBean = JSONObject.fromObject(obj,jsonConfig);
	return jsonFromBean;
}

	
}
